<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #dv1 {
            width: 300px;
            height: 200px;
            background-color: red;
        }

        #dv2 {
            width: 250px;
            height: 150px;
            background-color: green;
        }

        #dv3 {
            width: 200px;
            height: 100px;
            background-color: blue;
        }
    </style>
</head>

<body>
    <!-- 事件冒泡:多个元素嵌套,有层次关系,这些元素都注册了相同的事件,如果里面的元素的事件触发了,外面的元素的该事件自动的触发了.  -->
    <div id="dv1">
        <div id="dv2">
            <div id="dv3"></div>
        </div>
    </div>

    <script>


        function my$(id) {
            return document.getElementById(id);
        }     
        
        //阻止事件冒泡:
        // 1.window.event.cancelBubble=true; IE特有的,谷歌支持,火狐不支持
        // 2.e.stopPropagation(); 谷歌和火狐支持

        //阻止事件冒泡兼容方法
        function notEventBubbling(evene){
            if(evene){
                window.event.cancelBubble=true        
            } else {
                evene.stopPropagation()
            }
        }

        my$("dv1").onclick = function (evene) {
            console.log(this.id);
        };
        my$("dv2").onclick = function (evene) {
            console.log(this.id);

        };
        my$("dv3").onclick = function (evene) {
            console.log(this.id);
            notEventBubbling(evene)
        };

        document.body.onclick = function () {
            console.log("颤抖吧,你们这些愚蠢的标签");
        };


    </script>
</body>

</html>